import instance from '@/api/axiosConfig'
import urls from '../urls'
const { bookmark } = urls

// 所有书签
export function getBookmarks() {
    return instance({
        url: bookmark.list,
        method: 'get'
    })
}

// 添加书签
export function addBookmark(data: any) {
    return instance({
        url: bookmark.add,
        method: 'post',
        data: data
    })
}

// 更新widget状态
export function updateWidgetStatus(data: any) {
    return instance({
        url: bookmark.hide,
        method: 'put',
        data
    })
}

// 更新组件属性
export function updateWidgetProps(data: any) {
    return instance({
        url: bookmark.updateProp,
        method: 'put',
        data
    })
}

// 删除组件
export function deleteWidget(params: any) {
    return instance({
        url: bookmark.destory,
        method: 'delete',
        params: params
    })
}


export async function fetchUserBookmark(params: any) {
    // return instance.get("/api/extension/bookmarks", {
    //     params: params
    // });

    return fetch('http://localhost:5600/mock-json/bookmarks.json').then(res => {
        if (!res.ok) {
            throw new Error(`请求失败`)
        }
        return res.json()
    })
}

